﻿<cfparam name="Flag" type="string" default="">

<cfif isDefined("URL.flag")>
	<cfset Flag = "#URL.flag#">
<cfelse>
	<cflocation url="categories.cfm">
</cfif>
<html>
<head>
<script type="text/javascript">
function Ask(choice)
{
	if (choice == 'c')
	{
		ColdFusion.MessageBox.create('mb','Confirm','Confirm deletion','Are you sure?', confirmAction1);
	}
	else
	{
		ColdFusion.MessageBox.create('mb','Confirm','Confirm deletion','Are you sure?', confirmAction2);
	}
		ColdFusion.MessageBox.show('mb');		
}

var confirmAction1 = function(btn)
{
	if (btn == 'no')
	{
		location.replace("categories.cfm");				
	}
	else
	{
		location.replace("delete.cfm?del=1&flag=c");
	}
}
var confirmAction2 = function(btn)
{
	if (btn == 'no')
	{
		location.replace("redirect.cfm");				
	}
	else
	{
		location.replace("delete.cfm?del=1&flag=p");
	}
}
</script>
</head>
<body>
<cfmessagebox buttontype="yesno" icon="question"
			labelyes="Confirm" labelno="Cancel"
			message="Are you sure?" modal="true"
			name="DelMes" title="Confirm deleting"
			type="confirm"/>
<cfoutput>
<script>
	Ask("#Flag#");
</script>
</cfoutput>
<!---Delete Category--->
<cfif Flag IS "c">
	<cfif IsDefined("client.CategID") AND isDefined("URL.del")>
		<cfset CatObjDAO = createObject("component", "Catalog.DataAccessLayer.CategoriesDAO").init() />
		<cfset Categ = "#client.CategID#">
		<cfset CatObjDAO.delete(Categ)>
		<cfset client.delmes = "true">
		<cflocation url="categories.cfm">
	</cfif>
<cfelseif Flag IS "p">
<!---Delete Product--->
	<cfif IsDefined("client.ProdID") AND IsDefined("client.CatID") AND isDefined("URL.del")>
		<cfset ProdObjDAO = createObject("component", "Catalog.DataAccessLayer.ProductsDAO").init() />
		<cfset Pr = "#client.ProdID#">
		<cfset ProdObjDAO.delete(Pr)>
		<cfset client.delmes = "true">		
		<cflocation url="products.cfm?cat=#client.CatID#">
	</cfif>
</cfif>
</body>
</html>